<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        $res    = Db::query('SHOW TABLE STATUS');
        $tables = [];
        foreach ($res as $v) {
            array_push($tables, [
                'name'      => $v['Name'],//表名称
                'engine'    => $v['Engine'],//驱动
                'collation' => $v['Collation'],//字符集
                'comment'   => $v['Comment'],//备注信息
                'data_length'   => $v['Data_length'],//表的大小
                'data_length'   => $v['Data_length'],//表的大小
            ]);
        }
        //查询表
        foreach ($tables as &$val) {
            $tablesField    = Db::query("SHOW FULL FIELDS FROM `{$val['name']}`");
            $fields = [];
            foreach ($tablesField as $row) {
                array_push($fields, [
                    'Field'     => $row['Field'],
                    'Type'      => $row['Type'],
                    'Collation' => $row['Collation'],
                    'Null'      => $row['Null'],
                    'Key'       => $row['Key'],
                    'Default'   => $row['Default'],
                    'Extra'     => $row['Extra'],
                    'Comment'   => $row['Comment'],
                ]);
            }
            $val['field'] = $fields;
        }
        var_export($tables);die;

    }
}
